<?php
// +----------------------------------------------------------------------------
// | Tke团队版权所属 [三十年河东三十年河西,莫欺少年穷.!]
// +----------------------------------------------------------------------------
// | Copyright (c) 2014 http://www.itdaodan.com All rights reserved.
// +----------------------------------------------------------------------------
// | Author: sap<songaiping@hrbjjhh.com>
// +----------------------------------------------------------------------------
/**
 * @todo 活动班车地点视图模型
 +------------------------------------------------------------------------------
 * @version   1.0
 * @since 2015-8-19
 +------------------------------------------------------------------------------
 */
namespace Admin\Model;
use Think\Model\ViewModel;

class ActivityBusPointViewModel extends ViewModel{
	public $viewFields = array(
		'service_activity_bus' => array('*'),
		'service_bus' => array('departure_time','_on' => 'service_bus.activity_id = service_activity_bus.activity_id'),
	);

	/**
	 * @todo 获取活动下的班车点列表（建议缓存叫service_activity_bus_list）
	 * @param int activity_id 活动id
	 * @author PHP@妖孽 <dino_ma@163.com>
	 */
	public function getBusPoint($activity_id){
	    $map = array(
	        'service_bus' => 'service_activity_bus'
	    );
	    $activity_id = (int)$activity_id;
	    if($activity_id==0){
	        $this->error = '活动id有误';
	        return false;
	    }
	    $data = S('service_activity_bus_list');
	    $list = $data[$activity_id];
	    if(!$list){
	        $map = array();
	        $map['activity_id'] = $activity_id;
	        $list =  M('ServiceActivityBus')->where($map)->select();
	        S('service_activity_bus_list',array($activity_id=>$list));
	    }
	    return	$list;
	}
}